-
Notifications
You must be signed in to change notification settings - Fork 274
Error handling cleanup in solvers/flattening #2897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error handling cleanup in solvers/flattening #2897
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR failed Diffblue compatibility checks (cbmc commit: 40617c9).
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.
Common spurious failures:
- the cbmc commit has disappeared in the mean time (e.g. in a force-push)
- the author is not in the list of contributors (e.g. first-time contributors).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try to lift up invariants as far as possible. Several proposals below.
|
||
const exprt &op0=expr.op0(); | ||
DATA_INVARIANT( | ||
op0.type() == type, "add/sub with mixed types:\n" + expr.pretty()); | ||
|
||
bvt bv=convert_bv(op0); | ||
|
||
if(bv.size()!=width) | ||
throw "convert_add_sub: unexpected operand 0 width"; | ||
INVARIANT( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say a CHECK_RETURN
would do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But really: we are doing this all the time. Couldn't we just make convert_bv
take a second argument expected_width
and do that check itself? This will also take the error reporting one step closer to where the error occurred, helping to fix root causes, not symptoms.
@@ -69,17 +76,21 @@ bvt boolbvt::convert_add_sub(const exprt &expr) | |||
|
|||
const bvt &op=convert_bv(*it); | |||
|
|||
if(op.size()!=width) | |||
throw "convert_add_sub: unexpected operand width"; | |||
INVARIANT( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CHECK_RETURN
INVARIANT( | ||
op.size() == width, | ||
"the width of the bitvector resulting from the expression operand should" | ||
"be equal to the width indicated by the expression type"); | ||
|
||
if(type.id()==ID_vector || type.id()==ID_complex) | ||
{ | ||
const typet &subtype=ns.follow(type.subtype()); | ||
|
||
std::size_t sub_width=boolbv_width(subtype); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While at it: remove the ns.follow
in here, and let boolbv_width
deal with possible symbol/tag types (just pass type.subtype()
to boolbv_width
.
@@ -91,7 +102,8 @@ bvt boolbvt::convert_add_sub(const exprt &expr) | |||
|
|||
for(std::size_t j=0; j<tmp_op.size(); j++) | |||
{ | |||
assert(i*sub_width+j<op.size()); | |||
INVARIANT( | |||
i * sub_width + j < op.size(), "bit index shall be within bounds"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to check this tmp_op.size()
-times. We can just check this once before entering the loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The invariant is actually contained in a nested loop. It seems that the intention is also to check that we didn't mess up the index computation (e.g. by confusing i
and j
). How about we keep the invariant at this place and introduce a new local variable index
which is set to i * sub_width + j
and then use this variable in both the invariant and the array access?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, that would make sense.
@@ -100,7 +112,8 @@ bvt boolbvt::convert_add_sub(const exprt &expr) | |||
|
|||
for(std::size_t j=0; j<tmp_result.size(); j++) | |||
{ | |||
assert(i*sub_width+j<bv.size()); | |||
INVARIANT( | |||
i * sub_width + j < bv.size(), "bit index shall be within bounds"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above: check once, before entering the loop. And then consider whether it can be checked even earlier (as soon as all variables' values are known).
@@ -31,8 +34,10 @@ bvt boolbvt::convert_complex(const exprt &expr) | |||
{ | |||
const bvt &tmp=convert_bv(*it); | |||
|
|||
if(tmp.size()!=op_width) | |||
throw "convert_complex: unexpected operand width"; | |||
INVARIANT( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above.
@@ -47,6 +52,8 @@ bvt boolbvt::convert_complex(const exprt &expr) | |||
|
|||
bvt boolbvt::convert_complex_real(const exprt &expr) | |||
{ | |||
PRECONDITION(expr.id() == ID_complex_real); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could such an expression be introduced, with a proper API? I have no idea what that is, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to be for getting the real part of a complex number. The introduction of complex_real_exprt
and complex_imag_exprt
has become a separate PR now: #2916.
bv.resize(width); // chop | ||
|
||
return bv; | ||
} | ||
|
||
bvt boolbvt::convert_complex_imag(const exprt &expr) | ||
{ | ||
PRECONDITION(expr.id() == ID_complex_imag); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above: introduce a new complex_imag_exprt
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #2916.
bvt boolbvt::convert_concatenation(const exprt &expr) | ||
{ | ||
PRECONDITION(expr.id() == ID_concatenation); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use concatenation_exprt
as parameter to the method.
@@ -12,6 +12,8 @@ Author: Daniel Kroening, [email protected] | |||
|
|||
bvt boolbvt::convert_cond(const exprt &expr) | |||
{ | |||
PRECONDITION(expr.id() == ID_cond); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introduce a cond_exprt
(whatever that is).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ID_cond
is never assigned to anything, I would say remove it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to be a list of guarded commands, but as @romainbrenguier mentioned it's not assigned anywhere. @kroening Is this still needed or can we remove ID_cond
and convert_cond
?
40617c9
to
b9a0781
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR failed Diffblue compatibility checks (cbmc commit: 40617c9).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/83782391
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.
Common spurious failures:
- the cbmc commit has disappeared in the mean time (e.g. in a force-push)
- the author is not in the list of contributors (e.g. first-time contributors).
ee9241e
to
4e4bbe4
Compare
4e4bbe4
to
8896c52
Compare
01428ad
to
4a82359
Compare
src/solvers/flattening/boolbv.cpp
Outdated
it->var_no() != literalt::unused_var_no(), | ||
"variable number must be different from the unused variable number", | ||
expr.find_source_location(), | ||
expr.pretty()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you just pass expr
to INVARIANT_WITH_DIAGNOSTICS
as a structured argument rather than doing pretty() here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, this was done before the irep_pretty_diagnosticst
PR was merged. I think I have to do this in a few more places in the other PRs as well.
4a82359
to
7f58955
Compare
@kroening @tautschnig @peterschrammel There's two remaining questions in this PR regarding |
Deferring to @kroening @peterschrammel or @mgudemann: maybe EBMC has these? I don't know about the hardware stuff... |
They are both used in EBMC. |
Thanks. Could anyone with insight into that code base help out to provide code to go in |
7f58955
to
5f068f9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passed Diffblue compatibility checks (cbmc commit: 5f068f9).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/85324861
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good from my point of view, with some action items left.
@@ -69,7 +62,7 @@ bvt boolbvt::convert_complex_imag(const complex_imag_exprt &expr) | |||
|
|||
bvt bv = convert_bv(expr.op()); | |||
|
|||
assert(bv.size()==width*2); | |||
INVARIANT(bv.size() == width * 2, ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing message
@@ -54,7 +47,7 @@ bvt boolbvt::convert_complex_real(const complex_real_exprt &expr) | |||
|
|||
bvt bv = convert_bv(expr.op()); | |||
|
|||
assert(bv.size()==width*2); | |||
INVARIANT(bv.size() == width * 2, ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing message, though really you should just drop it and add the extra argument to convert_bv
?
5f068f9
to
6d22293
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passed Diffblue compatibility checks (cbmc commit: 6d22293).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/85673016
6d22293
to
af4df20
Compare
Files arrays.cpp to boolbv_cond.cpp (in alphabetical order)
af4df20
to
77e1b6c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passed Diffblue compatibility checks (cbmc commit: 77e1b6c).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/85739351
@danpoe, could you please raise an issue with all the expressions that you would like to be added? |
Ok, raised an issue for now for the remaining expression types: #3037 |
Error handling cleanup in
solvers/flattening
, filesarray.cpp
toboolbv_cond.cpp
(alphabetically).